import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/components/my_gesture_detector.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';

/**
 *
 * @Description TODO
 * @Author liuer
 * @CreateTime 2024年03月27日 19:23
 */
enum  PowerRankTabType {
  power,
  electricity,
  profit
}
class PowerRankTab extends StatefulWidget {
  // 类型
  PowerRankTabType type;
  // 第一个按钮文字
  final String string1;
  // 第二个按钮文字
  final String string2;
  // 第三个按钮文字
  final String string3;
  final Function(PowerRankTabType) callBack;

  PowerRankTab(this.type, this.callBack,
      {required this.string1,
      required this.string2,
      required this.string3,
      super.key});

  @override
  State<PowerRankTab> createState() => _PowerRankTabState();
}

class _PowerRankTabState extends State<PowerRankTab> {
  @override
  Widget build(BuildContext context) {
    // Log.d('widget.type==' + widget.type.toString());
    return Container(
      height: 32,
      margin: EdgeInsets.only(left: 16.w, right: 16.w),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          color: Colors.white,
          border: Border.all(color: Colour.primaryColor, width: 0.5)),
      child: Row(
        children: [
      Visibility(
      visible: widget.string1 != '',
        child: Expanded(
            flex: 1,
            child: MyGestureDetector(
              onTap: () {
                widget.type = PowerRankTabType.power;
                widget.callBack(widget.type);
                setState(() {});
              },
              child: Container(
                decoration: BoxDecoration(
                  borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(7),
                      bottomLeft: Radius.circular(7)),
                  color: widget.type == PowerRankTabType.power
                      ? Colour.primaryColor
                      : Colors.white,
                  // border: Border.all(color: Colour.primaryColor,width: 1)
                ),
                alignment: Alignment.center,
                child: Text(
                  widget.string1,
                  textAlign: TextAlign.center,
                  style: ytTextStyle(
                      fontSize: 14,
                      color: widget.type == PowerRankTabType.power
                          ? Colors.white
                          : Colour.primaryColor,
                      height: 1),
                ),
              ),
            ),
          )),
          Visibility(
            visible: widget.string1 != '',
            child: Container(
              height: 32,
              color: Colour.primaryColor,
              width: 0.5,
            ),
          ),
          Expanded(
            flex: 1,
            child: MyGestureDetector(
              onTap: () {
                widget.type = PowerRankTabType.electricity;
                widget.callBack(widget.type);
                setState(() {});
              },
              child: Container(
                decoration: widget.string1 == ''
                    ? BoxDecoration(
                        borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(7),
                            bottomLeft: Radius.circular(7)),
                        color: widget.type == PowerRankTabType.electricity
                            ? Colour.primaryColor
                            : Colors.white,
                        // border: Border.all(color: Colour.primaryColor,width: 1)
                      )
                    : BoxDecoration(
                        // borderRadius: const BorderRadius.only(topRight: Radius.circular(7),bottomRight: Radius.circular(7)),
                        color: widget.type == PowerRankTabType.electricity
                            ? Colour.primaryColor
                            : Colors.white,
                      ),
                alignment: Alignment.center,
                child: Text(
                  widget.string2,
                  textAlign: TextAlign.center,
                  style: ytTextStyle(
                      fontSize: 14,
                      height: 1,
                      color: widget.type == PowerRankTabType.electricity
                          ? Colors.white
                          : Colour.primaryColor),
                ),
              ),
            ),
          ),
        Visibility(
        visible: widget.string1 != '',
        child: Container(
            height: 32,
            color: Colour.primaryColor,
            width: 0.5,
          )),
         Expanded(
                flex: 1,
                child: MyGestureDetector(
                  onTap: () {
                    widget.type = PowerRankTabType.profit;
                    widget.callBack(widget.type);
                    setState(() {});
                  },
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: const BorderRadius.only(
                          topRight: Radius.circular(7),
                          bottomRight: Radius.circular(7)),
                      color: widget.type == PowerRankTabType.profit
                          ? Colour.primaryColor
                          : Colors.white,
                      // border: Border.all(color: Colour.primaryColor,width: 1)
                    ),
                    alignment: Alignment.center,
                    child: Text(
                      widget.string3,
                      textAlign: TextAlign.center,
                      style: ytTextStyle(
                          fontSize: 14,
                          height: 1,
                          color: widget.type == PowerRankTabType.profit
                              ? Colors.white
                              : Colour.primaryColor),
                    ),
                  ),
                ),
              ),
        ],
      ),
    );
  }
}
